package components
{
	import UIFree.ObjectEvent;
	import UIFree.uif_component;
	
	import classes.c_events;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.ui.Mouse;
	
	public class c_cursor extends c_component {
		private var _image			: Bitmap;
		private var _cursorsClasses : Object;
		private var _offset			: Point;
		
		public function c_cursor(parent:uif_component, a_cursorsClasses: Object) {
			super(parent);
			_cursorsClasses = a_cursorsClasses;
			_offset 		= new Point(12, 12);
		}
		
		override protected function listenEvents():void {
			super.listenEvents();
			addEvent(MouseEvent.MOUSE_MOVE, doMouseMove, stage);
			addEvent(c_events.SETCURSOR, doSetCursor, cl.workspace);
		}
		
		protected function doMouseMove(e: MouseEvent): void {
			if (_image) {
				_image.x = app.mouseX + _offset.x;
				_image.y = app.mouseY + _offset.y;
			}
		}
		
		protected function setCursor(cursorName: String=''): void {
			if (_image) {
				removeChild(_image);
				_image.bitmapData.dispose();
				_image = null;
			}
			if (_cursorsClasses.hasOwnProperty(cursorName)) {
				_image = new _cursorsClasses[cursorName]();
				addChild(_image);
			}
		}
		
		protected function doSetCursor(e: ObjectEvent): void {
			setCursor(e.object as String);
		}
	}
}